package io.wdb.modules.manager.job.capital;

import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.TimeZone;

import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;

import io.wdb.modules.manager.job.bookshelf.SchedulingConfig;
import io.wdb.modules.manager.job.task.CapitalSchedulTask;

@Configuration
@EnableScheduling
public class CapitalScheduleConfig {
	//填充Bean
	private Logger log = org.slf4j.LoggerFactory.getLogger(SchedulingConfig.class);
	@Autowired
	private CapitalSchedulTask capitalSchedulTask;
	
    /*public void scheduleCapitalSelect(Map<String,Object> params) {
		try {
			log.info("开始统计元数据信息======");
			Date startTime = new Date();
			if(params.get("selectTime")==null) {
				Date date = new Date();
				params.put("selectTime", date);
			}
			capitalSchedulTask.capitalDeposit(params);
			Date endTime = new Date();
			log.info("统计元数据信息花费时间为："+(endTime.getTime()-startTime.getTime()));
			log.info("统计元数据信息完成======"+params.get("selectTime"));
		} catch (Exception e) {
			log.error("统计元数据信息失败");
			log.error(e.getMessage(),e);
		}
    }*/
	@Scheduled(cron = "0 0 * * * ?") // 每20秒执行一次
    public void scheduleCapitalCurrent() {
		try {
			Map<String,Object> params = new HashMap<String,Object>();
			log.info("开始统计元数据信息======");
			Date startTime = new Date();
			Date date = new Date();
			Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("GMT-8"));
			calendar.setTime(date);
			calendar.add(Calendar.MINUTE, -20);
			params.put("selectTime", calendar.getTime());
			capitalSchedulTask.capitalDeposit(params);
			Date endTime = new Date();
			log.info("统计元数据信息花费时间为："+(endTime.getTime()-startTime.getTime()));
			log.info("统计元数据信息完成======"+params.get("selectTime"));
		} catch (Exception e) {
			log.error("统计元数据信息失败");
			log.error(e.getMessage(),e);
		}
    }
}
